package view;

import java.util.Calendar;

import controller.Controller;

@SuppressWarnings("serial")
public class TableModelMonth extends TableModelDefault {
	private Calendar cal = Calendar.getInstance();
	private int month;
	private int year;

	public TableModelMonth(Controller controller, int year, int month) {
		super(controller);
		this.year = year;
		this.month = month;

		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);

	}

	@Override
	public int getRowCount() {
		return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		if (columnIndex == 0) {
			return rowIndex + 1; // returns the day
		} else if (columnIndex == columnNames.indexOf(INCOMECOLUMN)) { // returns incomes on income column
			return controller.getModel().getDayIncomeSum(year, month,
					rowIndex + 1, null);
		} else {
			return controller.getModel().getDayExpenseSum(year, month,
					rowIndex + 1, getCategoryForModel(columnIndex), null);
		}
	}
}